package Lyl.wiki.controller;
import Lyl.wiki.req.EbookQueryReq;
import Lyl.wiki.req.EbookSaveReq;
import Lyl.wiki.resp.CommonResp;
import Lyl.wiki.resp.EbookQueryResp;
import Lyl.wiki.resp.PageResp;
import Lyl.wiki.service.EbookService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/ebook")
public class ebookcontroller {
    @Resource
    private EbookService ebookService;
    @GetMapping("list")
    public CommonResp list(@Valid EbookQueryReq req){
        //把查找结果放到列表中
        CommonResp<PageResp<EbookQueryResp>>  resp = new CommonResp<>();
        //创建一个CommonResp类型对象resp
        PageResp<EbookQueryResp> list =ebookService.list(req);
        //讲resp对象中的内容设置为查询结果列表list
        resp.setContent(list);
        //放回resp对象
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp =new CommonResp<>();
        ebookService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        return resp;
    }
}
